{% extends "base.html" %}
{% load custom_filters %}

{% block title %}Study Detail - {{ study.description }}{% endblock title%}

{% block scripts %}
	<script type="text/javascript" src="/javascript/jquery-1.3.2.js"></script> 
	<script type="text/javascript" src="/javascript/dataTables-1.4/media/js/jquery.dataTables.js"</script>
	<script type="text/javascript">
        $(document).ready(function() {
                $(".sortable").dataTable( {
                        "bPaginate": false,
                        });
                });
    	</script>
    	</script>

{% endblock scripts %}

{% block header %}Study Detail - {{ study.description }}{% endblock header%}

{% block content %}
	<ul>
	<li><a href=#summary>Summary</a></li>
	<li><a href=#experiments>Experiments</a></li>
	<li><a href=#animals>Animals</a></li>
	<li><a href=#data>Data</a></li>
	</ul>
<table>
	<thead>
	</thead>
	<tbody>
		<tr><th>Strain</th><td>{% for strain in study.strain.all %}<a href="/mousedb/strain/{{ strain.Strain_slug }}">{{ strain }}</a>{% endfor %}</td></tr>
		<tr><th>Start Date</th><td>{{ study.start_date }}</td></tr>
		<tr><th>End Date</th><td>{{ study.stop_date}}</td></tr>
		<tr><th>Notes</th><td>{{ study.notes }}</td></tr>
	</tbody>
	</table>
	
<div id = "experiments">
		<h2{{ study.experiment_set.all.count }} Experiments</h2>
		{% with study.experiment_set.all as experiment_list %}
		{% include "experiment_list_table.html" %}
		{% endwith %}
<p>Add new experiment <a href="/mousedb/study/{{study.id}}/experiment/new/">here</a></p>
</div>
<h3>{{ study.treatment_set.all.count }} Treatment(s):</h3>
<div id = "treatment_chart">
<img src="http://chart.apis.google.com/chart?chs=1000x250
&amp;chd=t:{% for treatment in study.treatment_set.all %}{{treatment.animals.all.count}}{% if not forloop.last %},{% endif %}{% endfor %}
&amp;cht=p3
&amp;chco=996666
&amp;chl={% for treatment in study.treatment_set.all %}{{treatment}} ({{treatment.animals.all.count}} Animals)|{% endfor %}"
title="Treatment Summary Chart"/>
</div>
{% for treatment in study.treatment_set.all %}
<div id = "treatment_summary">
	<h4>{{ treatment }}</h4>
	<ul>
	 <li>Diet: {{ treatment.diet }} - <a href="/mousedb/diet/{{treatment.diet.id}}">Detail</a></li>
	 <li>Location: {{ treatment.environment }}</li>
	 {% if treatment.pharmaceutical.all %}<li>Drug: {% for drug in treatment.pharmaceutical.all %}{{drug}} - <a href="/mousedb/pharmaceutical/{{drug.id}}">Details</a>{% endfor %}</li>{% endif %}
	 {% if treatment.implantation.all %}<li>Implantation: {{ treatment.implantation }}</li>{% endif %}
	 {% if treatment.transplantation %}<li>Transplantation: {{ treatment.transplantation }}</li>{% endif %}
	 {% if treatment.notes %}<li>Notes: {{ treatment.pharmaceutical.notes }}</li>{% endif %}
	</ul>
	<div id = "animals">
		<h4>{{ treatment.animals.all.count }} Animals</h4>
		{% with treatment.animals.all as animal_list %}
		{% include "animal_list_table.html" %}
		{% endwith %}
	</div>
</div>
{% endfor %}
	<div id="data">
	<h3>Experiments ({{ study.experiment_set.count}})</h3>
		{% with study.experiment_set.all as experiment_list %}
		{% for experiment in experiment_list %}
		{% with experiment.measurement_set.all as data_list %}
		{% include "data_table.html" %}
		{% endwith %}
		{% endfor %}
		{% endwith %}
	</div>

{% endblock content %}
